package com.sign2024.sign2024core.common.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class MyWebMvcConfigurer extends WebMvcConfigurationSupport {

    /**
     * 如果继承了WebMvcConfigurationSupport，静态资源配置会失效
     * 需要重新指定静态资源
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/");
        registry.addResourceHandler("doc.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/swagger-ui/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
        super.addResourceHandlers(registry);
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //是否发送Cookie
                .allowCredentials(true)
                //放行哪些原始域
                .allowedOriginPatterns("*")
                .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"})
                .allowedHeaders("*")
                .exposedHeaders("*");
    }

//    @Override
//    protected void addInterceptors(InterceptorRegistry registry) {
//        // 配置需要拦截的所有访问请求
//        String[] addPathPatterns = {
//                "/app/**"
////                "/**"
//        };
//        // 配置要排除的路径
//        String[] excludePathPatterns = {
//                "/app/login"
////                "/login"
//        };
//        // 注册拦截器
//        registry.addInterceptor(new LoginCheckInterceptor()).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
//        super.addInterceptors(registry);
//    }
}